<template>
    <div class="login">
      <el-form label-width="80px">
        <el-form-item label="账号" prop="username">
        <el-input ref="username" v-model="username" type="text" name="username"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="password">
    <el-input ref="password" v-model="password" type="password" name="password"></el-input>
  </el-form-item>
  <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form>
    </div>
</template>
<script>
import { login,loginOf } from '../../api/user'
export default {
data(){
  return{
      username:'',
      password:''
  }
},
  methods: {
      // onSubmit() {
        // login(this.loginNum)
        // if()
        onSubmit(){
          login({userName:this.username,password:this.password}).then(res=>{
            this.$router.push({name:'home'})
          })

          // if(localStorage.getItem('token')){
          //   this.$router.push({name:'home'})
          // }
          // const res = await loginOf({userName:this.username,password:this.password})
          // console.log(res)
        }
        // console.log(this.refs.loginNum)
        // this.$store.dispatch('/login',this.loginNum)
        // if(this.$refs.username.value == 'thc'){
        //   if(this.$refs.password.value == '8820'){
        //     this.$router.push({name:'home'})
        //   }else{
        //     alert("密码错误，请重新输入")
        //     this.$refs.username.value = ""
        //   this.$refs.password.value = ''
        //   }
        // }else{
        //   alert("用户名错误，请重新输入")
        //   this.$refs.username.value = ""
        //   this.$refs.password.value = ''
        // }
        // console.log(this.$refs.username.value,this.$refs.password.value)
      }
    // }
}
</script>
<style>
body{
  background:#EDAAAA no-repeat;
}
.login{
  width: 400px;
  height: 150px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
}
</style>
